<template>
  <!-- 机构业绩 -->
  <div class="app-container">
    <!-- 查询模块 -->
    <div class="formDiv">
      <el-form ref="form" :inline="true" :model="form" label-width="130px">
        <el-row>
          <el-col :span="8">
            <el-form-item label="服务商姓名/手机">
              <el-input v-model="form.service_name_or_phone" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="服务商级别">
              <el-select v-model="form.service_level" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in serviceLevel"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="是否入账">
              <el-select v-model="form.is_freeze" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in freeze"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="奖励时间" width="236">
              <el-date-picker
                v-model="time"
                value-format="yyyy-MM-dd HH:mm:ss"
                type="daterange"
                range-separator="-"
                start-placeholder="开始时间"
                end-placeholder="结束时间"
                :default-time="['00:00:00', '23:59:59']"
              />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="用户姓名/手机">
              <el-input v-model="form.user_name_or_phone" clearable />
            </el-form-item>
          </el-col>
          <!--          <el-col :span="8">-->
          <!--            <el-form-item label="客户姓名/手机号">-->
          <!--              <el-input v-model="form.referee" clearable />-->
          <!--            </el-form-item>-->
          <!--          </el-col>-->
          <el-col :span="8">
            <el-form-item label="订单编号">
              <el-input v-model="form.order_sn" clearable />
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="订单类型">
              <el-select v-model="form.order_type" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in orderType"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="8">
            <el-form-item label="奖励类型">
              <el-select v-model="form.order_status" placeholder="请选择" clearable>
                <el-option
                  v-for="(item,index) in statusType"
                  :key="index"
                  :label="item.name"
                  :value="item.value"
                />
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :span="6" :offset="18">
            <el-form-item>
              <el-button type="primary" @click="handleSearch">查询</el-button>
              <!-- <el-button type="primary" @click="handleExport">导出</el-button> -->
              <!-- <Exprotcomponent :params="form" url="admin/order/card_ticket_export" type="php"></Exprotcomponent> -->
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </div>
    <!-- 主页列表 -->
    <div v-loading="tableLoading" class="listDiv">
      <el-table ref="tableData" :data="tableData" style="width: 100%" height="500px">
        <!--   -->
        <el-table-column
          fixed
          type="index"
          label="序号"
          width="50"
          align="center"
          :index="table_index"
        />
        <el-table-column label="订单编号" prop="oder_sn" align="center">
          <template slot-scope="scope">
            <div>{{ scope.row.oder_sn == 0 ?"" : scope.row.oder_sn }}</div>
          </template>
        </el-table-column>
        <el-table-column label="订单类型" prop="order_type" align="center" width="120px" />
        <el-table-column label="用户姓名" prop="real_name" align="center" width="120px" />
        <el-table-column label="用户手机号" prop="phone" align="center" width="120px" />
        <el-table-column label="奖励金额" prop="reward_amount" align="center" width="120px" />
        <el-table-column label="税费" prop="tax_amount" align="center" width="120px" />
        <el-table-column label="入账金额" prop="amount" align="center" width="120px" />
        <el-table-column label="是否入账" prop="is_get_in" align="center" width="120px" />
        <el-table-column label="奖励服务商" prop="reward_name" align="center" width="120px" />
        <el-table-column label="奖励手机号" prop="reward_phone" align="center" width="120px" />
        <el-table-column label="奖励级别" prop="reward_level" align="center" width="120px" />
        <el-table-column label="奖励类型" prop="reward_type" align="center" width="120px" />
        <el-table-column label="奖励时间" prop="reward_time" align="center" width="200px">
          <!--          <template slot-scope="scope">-->
          <!--            <span v-if="scope.row.pay_time">{{(scope.row.pay_time-0)*1000| date(1)}}</span>-->
          <!--            &lt;!&ndash; <span v-else></span> &ndash;&gt;-->
          <!--          </template>-->
        </el-table-column>
      </el-table>
      <!-- 分页 -->
      <div class="pagesCon">
        <div>
          <el-pagination
            :current-page="form.page"
            :page-sizes="page_sizes"
            :page-size="form.perpage"
            layout="total, sizes, prev, pager, next, jumper"
            :total="page_totals"
            @size-change="handleSizeChange"
            @current-change="handleCurrentChange"
          />
        </div>
      </div>
    </div>
  </div>
</template>

<script>

import commonFn from '@/utils/common'
import filter from '@/assets/filter'
import { get_service_reward_list } from '../../api/ServiceManagement'
export default {
  name: 'GiftBagOrder',
  filters: {
    nullFn(opt) {
      if (opt) {
        return opt
      } else {
        return '--'
      }
    },
    // 无数据显示
    noFn(opt) {
      if (opt) {
        return opt
      } else {
        return ''
      }
    }
  },
  data() {
    return {
      time: [],
      form: {
        service_name_or_phone: '', //	服务商姓名或者手机号
        user_name_or_phone: '', // 用户姓名或者手机号
        service_level: '', //	服务等级
        is_freeze: '', //	是否冻结
        start_time: '', //	开始时间
        end_time: '', //	结束时间
        order_sn: '', //	订单编号
        order_type: '', //	订单级别
        reward_type: '', //	订单类型
        page: 1,
        perpage: 10
      },
      // 分页
      page_sizes: [10, 30, 50, 100], // 每页显示个数
      page_totals: 0, // 总条目数,
      // 服务商级别   特约授权经销商、高级授权经销商、普通合伙人授权经销商、高级合伙人授权经销商
      // 1	普通会员	2特约授权经销商  3	高级授权经销商 4	普通会员 5普通会员			 6	普通会员	7	普通合伙人授权经销    8高级合伙人授权经销商		 9省级运营中心
      serviceLevel: [
        { name: '普通会员', value: 1 },
        { name: '特约授权经销商', value: 2 },
        { name: '高级授权经销商', value: 3 },
        { name: '普通合伙人授权经销', value: 7 },
        { name: '高级合伙人授权经销商', value: 8 },
        { name: '省级运营中心', value: 9 }
      ],
      // 是否入账
      freeze: [
        { name: '是', value: 1 }
        // { name: "否", value: 2 },
      ],
      // 订单类型  1会员卡 2项目
      orderType: [
        { name: '项目', value: 2 },
        { name: '会员卡', value: 1 }
      ],
      // 奖励类型  项目直推奖励、项目间推奖励、一次性补贴、团队奖励、大区奖励
      // 1 一级服务商奖励2 二级服务商奖励
      statusType: [
        { name: '一级服务商奖励', value: 1 },
        { name: '二级服务商奖励', value: 2 }
        // { name: "奖励类型", value: 1 },
        // { name: "项目直推奖励", value: 2 },
        // { name: "项目间推奖励", value: 3 },
        // { name: "一次性补贴", value: 4 },
        // { name: "团队奖励", value: 5 },
        // { name: "大区奖励", value: 6 },
      ],
      tableData: [],
      tableLoading: false,
      infoLoading: true
    }
  },
  watch: {
    time(val) {
      this.form.start_time = val ? val[0] : ''
      this.form.end_time = val ? val[1] : ''
    }
  },
  created() {
  },
  //新加路由保存参数
  beforeRouteLeave(to, from, next) {
    // const answer = window.confirm("当前页面搜索条件将会被保存");
    //更新 put
    let keyname = this.$route.name;
    let value = JSON.stringify(this.form);
    sessionStorage.setItem(keyname, value);
    next();
  },

  mounted() {
    // 获取默认列表
    if (sessionStorage.getItem(this.$route.name)) {
      this.form = JSON.parse(sessionStorage.getItem(this.$route.name));
    }
    this.getList(this.form)

  },
  methods: {
    toRoutes(name) {
      const route = { name }
      this.$router.push(route)
    },
    // 序号
    table_index(index) {
      return (this.form.page - 1) * this.form.perpage + index + 1
    },
    // 获取列表
    getList(e) {
      get_service_reward_list(e)
        .then(res => {
          if (res.data.code == 200) {
            this.tableData = res.data.data
            this.page_totals = res.data.meta.total
          } else {
            this.$message({
              showClose: true,
              message: res.data.msg,
              type: 'warning'
            })
          }
          this.tableLoading = false
        })
        .catch(err => {
          this.errorStatus(err.msg)
          this.tableLoading = false
        })
    },
    // 查询
    handleSearch() {
      this.form.page = 1
      this.getList(this.form)
    },

    // 导出
    handleExport() {
      const datas = { ...this.form }
      delete datas.page
      delete datas.perpage
      orderExport(datas)
        .then(res => {
          commonFn.downFile('导出', res)
        })
        .catch(err => {
          this.errorStatus(err.msg)
        })
    },
    // 改变页面条数
    handleSizeChange(val) {
      this.form.perpage = val
      this.getList(this.form)
    },
    // 选择页数
    handleCurrentChange(val) {
      this.form.page = val
      this.getList(this.form)
    },
    // // 弹窗组件
    eleMsg(txt, status) {
      this.$message({
        showClose: true,
        message: txt,
        type: status
      })
    },
    // 失败状态弹窗
    errorStatus(txt) {
      this.eleMsg(txt, 'error')
    }
  }
}
</script>
<style scoped>
.app-container {
  padding: 20px !important;
  background: transparent;
}
/* 主页列表样式 */
.listDiv {
  margin-bottom: 20px;
  padding: 0 20px;
}
.el-range-editor--medium.el-input__inner {
  width: 236px;
}
.pagesCon {
  text-align: right;
  margin-top: 20px;
}
.allCenter {
  text-align: center;
}
.spanToInput {
  width: 205px;
  min-height: 30px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  display: block;
  border: 1px solid #ddd;
  text-align: left;
  padding: 0 12px;
}
.line {
  height: 25px;
  background: #f7f7f7;
}
.recommend {
  min-width: 280px;
  color: #1d2023;
  text-align: center;
  font-size: 16px;
  margin-left: 25px;
}
.boxContent {
  margin-top: 20px;
  height: 25px;
  line-height: 25px;
  border: 1px solid #ddd;
  text-align: center;
  padding: 0 12px;
}
.arrow {
  text-align: center;
  padding: 12px 0 0 0;
}
.fontColor {
  font-size: 16px;
  text-align: center;
  margin-bottom: 15px;
}
.mb_20 {
  font-size: 20px;
  text-align: center;
  margin-top: 20px;
}
</style>
